package com.applet.controller.admin;

import com.applet.common.vo.Result;
import com.applet.pojo.dto.PublishVideoDTO;
import com.applet.pojo.dto.UpdateVideoDTO;
import com.applet.pojo.vo.ActivityDetailsVO;
import com.applet.pojo.vo.VideoVO;
import com.applet.service.VideoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author “XuShao”
 * @date 2024/12/17 16:40
 * @description
 */
@RestController
@RequestMapping("/admin/video")
@Tag(name = "视频相关接口")
@Slf4j
public class VideoController {

    @Autowired
    private VideoService videoService;

    @Operation(summary = "新增视频")
    @PostMapping
    public Result<?> addVideo(@RequestBody PublishVideoDTO publishVideoDTO) {
        log.info("新增视频 => {}", publishVideoDTO);

        videoService.addVideo(publishVideoDTO);

        return Result.success();
    }

    @Operation(summary = "修改视频")
    @PutMapping
    public Result<?> updateVideo(@RequestBody @Validated UpdateVideoDTO updateVideoDTO) {
        log.info("修改视频 => {}", updateVideoDTO);

        videoService.updateVideo(updateVideoDTO);

        return Result.success();
    }

    @Operation(summary = "获取所有视频")
    @GetMapping
    public Result<List<VideoVO>> getAllVideo() {
        log.info("=== 获取所有视频 ===");

        List<VideoVO> allVideo = videoService.getAllVideo();

        return Result.success(allVideo);
    }

    @Operation(summary = "根据id删除视频")
    @DeleteMapping("{id}")
    public Result<?> deleteVideo(@PathVariable String id) {
        log.info("根据id删除视频 => {}", id);

        videoService.deleteVideo(id);

        return Result.success();
    }
}
